from schablonesk.logic.comparison import Comparison
from schablonesk.logic.const_true import ConstTrue
from .branches_block import BranchesBlock


class CaseBlockBuilder(object):
    
    def __init__(self, switcher_expr):
        self.__switcher = switcher_expr
        self.__branches = []
        
    def add_when(self, criteria_expr, block):
        comparison = Comparison(self.__switcher, criteria_expr)
        self.__branches.append((block, comparison))
        
    def add_default(block):
        self.__branches.append((block, ConstTrue())

    def build(self):
        branches = BranchesBlock()
        for block, condition in self.__branches:
            branches.add_branch(block, condition)
        return branches
        